package com.laiyima.zhongjiang.linghuilv.demo.Serviceprovider;


import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.popupwindowlibrary.bean.FiltrateBean;
import com.example.popupwindowlibrary.view.ScreenPopWindow;
import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.view.CustomPartShadowPopupView;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.SimpleCallback;

import org.wangchenlong.datescroller.widget.DateScrollerDialog;
import org.wangchenlong.datescroller.widget.data.Type;
import org.wangchenlong.datescroller.widget.listener.OnDateSetListener;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import me.imid.swipebacklayout.lib.app.SwipeBackActivity;


public class BillDetailsActivity extends SwipeBackActivity implements View.OnClickListener {
    private String TAG="BillDetailsActivity";
    private int bdCode;
    private LinearLayout myback,bd_selectLin,bd_timeLin;
    private TextView bd_selectText,bd_timeText,bd_find,show_bdpop;
    private ImageView bd_selectImage,bd_timeImage;
    private boolean select=true,timeselse=true;

    private static final long HUNDRED_YEARS = 100L * 365 * 1000 * 60 * 60 * 24L;
    private long mLastTime = System.currentTimeMillis();
    private SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM", Locale.ENGLISH);
    private String myTime;


    private CustomPartShadowPopupView popupView;
    private ScreenPopWindow screenPopWindow;
    private List<FiltrateBean> dictList=new ArrayList();
    protected boolean useThemestatusBarColor = false;//是否使用特殊的标题栏背景颜色，android5.0以上可以设置状态栏背景色，如果不使用则使用透明色值
    protected void setStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            //根据上面设置是否对状态栏单独设置颜色
            if (useThemestatusBarColor) {
                // getWindow().setStatusBarColor(getResources().getColor(R.color.colorTheme));
            } else {
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) {//android6.0以后可以对状态栏文字颜色和图标进行修改
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bill_details);
        myback= (LinearLayout) findViewById(R.id.bd_back);
        myback.setOnClickListener(this);
        bd_selectLin= (LinearLayout) findViewById(R.id.bd_selectLin);
        bd_selectLin.setOnClickListener(this);
        bd_timeLin= (LinearLayout) findViewById(R.id.bd_timeLin);
        bd_timeLin.setOnClickListener(this);
        bd_selectImage= (ImageView) findViewById(R.id.bd_selectImage);
        bd_timeImage= (ImageView) findViewById(R.id.bd_timeImage);
        bd_selectText= (TextView) findViewById(R.id.bd_selectText);
        bd_timeText= (TextView) findViewById(R.id.bd_timeText);
        show_bdpop= (TextView) findViewById(R.id.show_bdpop);

        setStatusBar();



      //  initParam();
    }

    @Override
    public void onClick(View v) {
        int id=v.getId();
        switch (id){
            case R.id.bd_back:
                finish();
                break;
            case R.id.bd_selectLin:
                if(select){
                    select=false;
                    timeselse=true;
                    showPartShadow(v);
                    bd_selectText.setTextColor(Color.parseColor("#126AE4"));
                    bd_selectImage.setImageResource(R.drawable.bdselect);
                    bd_timeText.setTextColor(Color.parseColor("#333333"));
                    bd_timeImage.setImageResource(R.drawable.agent_xiala);

                }else{
                    select=true;
                    bd_selectText.setTextColor(Color.parseColor("#333333"));
                    bd_selectImage.setImageResource(R.drawable.agent_xiala);
                }
                break;
            case R.id.bd_timeLin:
                if(timeselse){
                    timeselse=false;
                    select=true;
                    shoewtime();
                    bd_timeText.setTextColor(Color.parseColor("#126AE4"));
                    bd_timeImage.setImageResource(R.drawable.bdselect);
                    bd_selectText.setTextColor(Color.parseColor("#333333"));
                    bd_selectImage.setImageResource(R.drawable.agent_xiala);
                }else{
                    timeselse=true;
                    bd_timeText.setText("时间");
                    bd_timeText.setTextColor(Color.parseColor("#333333"));
                    bd_timeImage.setImageResource(R.drawable.agent_xiala);
                }


                break;

        }
    }
    private void showPartShadow(final View v){
        if(popupView==null){
            popupView = (CustomPartShadowPopupView) new XPopup.Builder(this)
                    .atView(v)
                    .setPopupCallback(new SimpleCallback() {
                        @Override
                        public void onShow() {
                         }
                        @Override
                        public void onDismiss() {

                         }
                    })
                    .asCustom(new CustomPartShadowPopupView(this));
         }

        popupView.show();
    }


    private void popShow() {
        this.screenPopWindow = new ScreenPopWindow(this, this.dictList);
        this.screenPopWindow.reset().build();
        this.screenPopWindow.showAsDropDown(this.show_bdpop);
        this.screenPopWindow.setOnConfirmClickListener(new ScreenPopWindow.OnConfirmClickListener() {
            public void onConfirmClick(List<String> list) {
                StringBuilder str = new StringBuilder();
                Log.e(BillDetailsActivity.this.TAG, "dictList.size():" + BillDetailsActivity.this.dictList.size());

                for(int i = 0; i < list.size(); ++i) {
                    str.append((String)list.get(i)).append(" ");
                }
                Toast.makeText(BillDetailsActivity.this, str.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }
    private void initParam() {
        String[] brand = new String[]{"全部", "通过", "审核中", "未通过"};
        FiltrateBean fb1 = new FiltrateBean();
        List<FiltrateBean.Children> childrenList = new ArrayList();
        String[] var4 = brand;
        int var5 = brand.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            String aBrand = var4[var6];
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(aBrand);
            childrenList.add(cd);
        }

        fb1.setChildren(childrenList);
        this.dictList.add(fb1);
    }



    private void shoewtime() {
        DateScrollerDialog dialog = new DateScrollerDialog.Builder()
                .setType(Type.YEAR_MONTH)
                .setMinMilliseconds(System.currentTimeMillis() - HUNDRED_YEARS)
                .setMaxMilliseconds(System.currentTimeMillis())
                .setCurMilliseconds(mLastTime)
                .setCallback(mOnDateSetListener)
                .build();


        if (dialog != null) {
            if (!dialog.isAdded()) {
                dialog.show(getFragmentManager(), "year_month_day");
            }
        }


    }
    public String getDateToString(long time) {
        Date d = new Date(time);
        return sf.format(d);
    }
    private final OnDateSetListener mOnDateSetListener = new OnDateSetListener() {
        @Override
        public void onDateSet(DateScrollerDialog timePickerView, long milliseconds) {
            mLastTime = milliseconds;
            myTime = getDateToString(milliseconds);
           // bd_timeText.setText(myTime);
          // myTime=myTime.substring(0,7);
          }
    };
}
